import { _decorator, Component, Node, Prefab, instantiate, Vec3, utils} from 'cc';
import { CardManager } from "./CardManager";
import { Card } from "./Card";

import  Util  from "./Util";
const { ccclass, property } = _decorator;

@ccclass('CpgStack') // 用 @ccclass 声明类为 Cocos 组件
export class CpgStack extends Component {

    @property([Node]) cardNodes: Node[] = [];



    onLoad() {

    }

    setData(cardIDs:number[]) {

        const cardCount = cardIDs.length;

        let showIndex = 1;
        if( cardCount == 4)
            showIndex = 3;

        for(let i = 0; i < cardCount; i++)
        {
            this.cardNodes[i].active = true;
            const cardNode = CardManager.createDeskCard(true);
            const card = cardNode.getComponent(Card);
            card?.setCardID(cardIDs[i]);
            if(i == showIndex)
            {
                card?.setArrow( Util.getRandomNumber(0, 3) );
            }

            this.cardNodes[i].addChild(cardNode);
        }

    }


}